home *** CD-ROM | disk | FTP | other *** search
/ WINMX Assorted Textfiles / Ebooks.tar / Text - Tech - Hacking - SoftIce - How to load IDA symbols into SoftICE (TXT).zip / MAP2MAP.PL < prev   
Perl Script  |  1998-06-21  |  2KB  |  141 lines

  1. #!/usr/bin/perl
  2. #
  3. # This Is Purl. Get With It.
  4. #
  5. # Title: Map2Map
  6. # Purpose: Convert IDA Ouput MAP files into A format usable by msym.exe
  7. # Use: "perl map2map.pl file.map > output.map", new file will be dumped to file
  8. # Coding Time: 50 minutes
  9. # Version: 0.2
  10. # Elegence Score: Don't even Ask
  11. #
  12. # Coded By Gij
  13. # 15/Jun/98
  14.  
  15.  if ( $#ARGV == -1 ) {
  16.     print "\nGij's Map2Map\n";
  17.     print "_-_-_-_-_-_-_\n\n";
  18.     print "Use: perl map2map.pl file.map [-kill:str1,str2,strn]/[-minimal]\n\n";
  19.     print "-kill: kills any symbol containing the specified string,\n";
  20.     print "       Preceede With '^', to kill only symbols STARTING with that\n";
  21.     print "       String.\n";
  22.     print "       Append '\$', to kill only symbols that END with that string.\n";
  23.         print "       Basicly, you can use an RE to eliminate labels by name. \n\n";
  24.     print "-minimal: Kills All symbols starting with dword,word,byte,loc,sub,unk\n";
  25.  
  26.     exit;
  27.  }
  28.  
  29.  foreach $_ (@ARGV) {
  30.     if ( /-minimal/i ) {
  31.         push @kill_list,"dword","word","loc","sub_","off","unk","byte";
  32.     }
  33.     elsif ( /-kill/i ) {
  34.         @_=split(/[,:]/);
  35.         @_= @_[ 1 .. $#_ ];
  36.         push @kill_list,@_;
  37.     }
  38.  }
  39.  
  40.  open FH,$ARGV[0];  
  41.  
  42.  
  43.  while ( <FH> ) {
  44.      if ( ! /^$/ ) {
  45.         last;
  46.      }
  47.  }
  48.  
  49.  
  50.  if( ! /(\w+)\s+(\w+)\s+(\w+)\s+\w+\s+(\w+)/i ) {
  51.     print "Error: Unkown File Format\n";
  52.     exit;
  53.  }
  54.  else {
  55.      print " $1 $2 $3 $4\n\n";
  56.  }
  57.  
  58.  
  59.  while ( <FH> ) {
  60.      if ( ! /^$/ ) {
  61.         last;
  62.      }
  63.  }
  64.  
  65.  
  66.  while ( ! eof FH ) {
  67.         if ( /^$/ ) {    
  68.         last;
  69.      }
  70.  
  71.     if( /([\dabcdef]+)H\s+[\dabcdef]+H\s+([\dabcdef]+)H\s+([\w\.]+)\s+(\w*)/i ) {
  72.     print " $1 $2 $3 $4\n";
  73.     }    
  74.     $_ = <FH>;
  75.  } 
  76.  
  77.  print "\n\n";
  78.  
  79.  while ( <FH> ) {
  80.      if ( ! /^$/ ) {
  81.         last;
  82.      }
  83.  }
  84.  
  85.  if( /(\w+)\s+(\w+)\s+(\w+)\s+(\w+)/i ) {
  86.      print " $1 $2 $3 $4\n\n";
  87.  
  88.  }
  89.  else {
  90.     print "Can't find start of publics\n";
  91.     exit;
  92.  }
  93.  
  94.  while ( <FH> ) {
  95.      if ( ! /^$/ ) {
  96.         last;
  97.      }
  98.  }
  99.  
  100.  while ( ! eof FH ) {
  101.     if ( /^$/ ) {    
  102.         last;
  103.      }
  104.  
  105.     if( /([\dabcdef]+)\:([\dabcdef]+)\s+(.+)/i ) {
  106.         $temp_sym_name = $3;
  107.         foreach $pat ( @kill_list ) {
  108.             if ( $temp_sym_name =~ /$pat/i ) {
  109.                 goto READ_LINE;          # argh, a goto, blorght'll kill me :)
  110.             }
  111.         }
  112.     
  113.         printf " %04x:%08x\t%s\n",hex $1,hex $2,$3;
  114.     }
  115.     else {
  116.         print "Error: Where Are the Symbols?\n";
  117.         exit;
  118.     }
  119.  
  120. READ_LINE:
  121.     $_ = <FH>;
  122.  } 
  123.  
  124.  while ( <FH> ) {
  125.      if ( ! /^$/ ) {
  126.         last;
  127.      }
  128.  }
  129.  
  130.  print "\n";
  131.  print;
  132.  
  133.  while ( ! eof FH ) {
  134.     print;
  135.     $_ = <FH>;
  136.  } 
  137.  
  138.  
  139.  
  140.  
  141.